package com.elong.businesstravel.modules.home.adapter;

import java.util.ArrayList;
import java.util.List;

import com.android.support.jhf.utils.ScreenUtils;
import com.android.support.jhf.utils.ToolUtils;
import com.elong.businesstravel.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SimpleGridDialogAdapter extends BaseAdapter {
	
	private List<String> mStrings;
	private Context mContext;
	private String mSelect;
	private List<String> mDisable = new ArrayList<String>();
	
	private int mScreenWidth;
	private int mScreenHeight;
	
	private int mItemWidth;
	private int mItemHeight;
	
	public SimpleGridDialogAdapter(Context context, List<String> strings, String select, List<String> disable) {
		mContext = context;
		mStrings = strings;
		mSelect = select;
		mDisable = disable;
		
		mScreenWidth = ScreenUtils.getScreenBounds(mContext)[0];
		mScreenHeight = ScreenUtils.getScreenBounds(mContext)[1];
		
		mItemWidth = mScreenWidth/2;
		
		mItemHeight = ToolUtils.dipToPx(mContext, 40);
	}
	
	public SimpleGridDialogAdapter(Context context, List<String> strings, String select) {
		mContext = context;
		mStrings = strings;
		mSelect = select;
		
		mScreenWidth = ScreenUtils.getScreenBounds(mContext)[0];
		mScreenHeight = ScreenUtils.getScreenBounds(mContext)[1];
		
		mItemWidth = mScreenWidth/2;
		
		mItemHeight = ToolUtils.dipToPx(mContext, 40);
	}
	
	@Override
	public int getCount() {
		return mStrings.size();
	}

	@Override
	public Object getItem(int position) {
		return mStrings.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(null == convertView){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.view_simple_grid_item, null);
		}
		
		TextView itemTextView = (TextView)convertView.findViewById(R.id.itemTextView);
		itemTextView.setText(mStrings.get(position));
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, mItemHeight);
//		layoutParams.leftMargin = 2;
//		layoutParams.rightMargin = 1;
//		layoutParams.topMargin = 2;
//		layoutParams.bottomMargin = 2;
		itemTextView.setLayoutParams(layoutParams);
		
//		ViewGroup simpleLayout = (ViewGroup)convertView.findViewById(R.id.simpleLayout);
		if(mSelect.equals(mStrings.get(position))){
			itemTextView.setSelected(true);
		}else {
			itemTextView.setSelected(false);
		}
		itemTextView.setTextColor(mContext.getResources().getColor(android.R.color.black));
		for (int i = 0; i < mDisable.size(); i++) {
			if(mDisable.get(i).equals(mStrings.get(position))){
				itemTextView.setTextColor(mContext.getResources().getColor(R.color.list_gray_text_color));
			}
		}
		
		return convertView;
	}

}
